import { deleteCourse,getCourseList,batchDeleteCourse,queryCourse,addCourse,modifyCourse} from "../../api/course.js";
const state = {
}
const mutations = { // mutations改变state中的数据
    NULL:()=>{}
}
const actions ={
    getCourseList({commit},data){
        const info={
            collegeId:data.collegeId, //获取管理员ID（需要改动）
            currentPage:data.currentPage,
            rows:data.rows,
            token:data.token,
        };
        return new Promise((resolve, reject) => {
            getCourseList(info).then( data => {
                if(data.code === 1){ // 获取课程信息成功
                    commit('NULL');
                    resolve(data);
                }else{
                    reject(data)
                }
            })
        })
    },
    deleteCourse({commit},data){
        return new Promise((resolve, reject) => {
            deleteCourse({courseId:data.courseId,token:data.token}).then( data => {
                if(data.code === 1){ // 删除成功
                    commit('NULL');
                    resolve(data);
                }else{
                    reject(data)
                }
            })
        })
    },
    deleteBatchCourse({commit},data){
        return new Promise((resolve, reject) => {
            batchDeleteCourse({courseIds:data.courseIds,token:data.token}).then( data => {
                if(data.code === 1){ // 删除成功
                    commit('NULL');
                    resolve(data);
                }else{
                    reject(data)
                }
            })
        })
    },
    queryCourse({commit},data){
        const info={
            courseName:data.courseName,
            collegeId:data.collegeId,
            currentPage:data.currentPage,
            rows:data.rows,
            token:data.token,
        };
        return new Promise((resolve, reject) => {
            queryCourse(info).then( data => {
                if(data.code === 1){ // 查询成功
                    commit('NULL');
                    resolve(data);

                }else{
                    reject(data)
                }
            })
        })
    },
    addCourse({commit},data){

        return new Promise((resolve, reject) => {
            addCourse({courseRecord: data.courseRecord,token:data.token}).then( data => {
                if(data.code === 1){ // 查询成功
                    commit('NULL');
                    resolve(data);
                }else{
                    reject(data)
                }
            })
        })
    },
    modifyCourse({commit},data){
        return new Promise((resolve, reject) => {
            modifyCourse({courseRecord:data.courseRecord,token:data.token})
            .then( data => {
                if(data.code === 1){ // 修改成功
                    commit('NULL');
                    resolve(data);
                }else{
                    reject(data)
                }
            })
        })
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}